/*
 * @lc app=leetcode.cn id=665 lang=javascript
 *
 * [665] 非递减数列
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {boolean}
 */
var checkPossibility = function(nums) {
    let temp=[...nums]
    for(let i=0;i<nums.length-1;i++){
        if(nums[i]>nums[i+1]){nums[i]=nums[i+1];temp[i+1]=temp[i]; break}
    }
    let arr1=[...nums]
    let arr2=[...temp]
    return arr1.toString()==nums.sort((a,b)=>a-b).toString()||arr2.toString()==temp.sort((a,b)=>a-b).toString()
};
// @lc code=end
checkPossibility([5,7,1,8])
